<template>
  <view class="login-container">
    <view class="login-background"></view>
    <view class="login-content">
      <view class="login-form">
        <text class="login-title">系统登录</text>
        
        <view class="input-group">
          <input 
            v-model="username" 
            class="input-field" 
            placeholder="请输入用户名" 
            placeholder-class="placeholder-style"
          />
          <input 
            v-model="password" 
            class="input-field" 
            password 
            placeholder="请输入密码" 
            placeholder-class="placeholder-style"
          />
        </view>
        
        <button class="login-btn" @click="handleLogin" :disabled="loading">
          {{ loading ? '登录中...' : '登录' }}
        </button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      loading: false
    }
  },
  methods: {
    async handleLogin() {
      if (!this.username || !this.password) {
        uni.showToast({
          title: '请输入用户名和密码',
          icon: 'none'
        });
        return;
      }
      
      this.loading = true;
      
      try {
        // 这里调用您的登录API
        // const result = await this.$api.login({
        //   username: this.username,
        //   password: this.password
        // });
        
        // 模拟登录成功
        setTimeout(() => {
          // 存储登录状态
          uni.setStorageSync('token', 'your-token-here');
          uni.setStorageSync('userInfo', { username: this.username });
          
          // 跳转到主布局页面
          uni.redirectTo({
            url: '/pages/main/layout'
          });
          
          this.loading = false;
        }, 1500);
        
      } catch (error) {
        this.loading = false;
        uni.showToast({
          title: '登录失败',
          icon: 'none'
        });
      }
    }
  },
  
  onLoad() {
    // 检查是否已登录
    const token = uni.getStorageSync('token');
    if (token) {
      uni.redirectTo({
        url: '/pages/main/layout'
      });
    }
  }
}
</script>

<style>
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-background {
  position: absolute;
  width: 100%;
  height: 100%;
}

.login-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 400rpx;
}

.login-form {
  background: rgba(255, 255, 255, 0.95);
  padding: 60rpx 40rpx;
  border-radius: 20rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}

.login-title {
  font-size: 36rpx;
  font-weight: bold;
  text-align: center;
  margin-bottom: 50rpx;
  display: block;
  color: #333;
}

.input-group {
  margin-bottom: 50rpx;
}

.input-field {
  width: 100%;
  height: 80rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 10rpx;
  padding: 0 20rpx;
  margin-bottom: 30rpx;
  font-size: 28rpx;
  background: white;
}

.input-field:focus {
  border-color: #667eea;
}

.placeholder-style {
  color: #999;
  font-size: 28rpx;
}

.login-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 10rpx;
  height: 80rpx;
  line-height: 80rpx;
  font-size: 32rpx;
}

.login-btn:disabled {
  opacity: 0.6;
}
</style>